home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / popup / popupstack.pyo (.txt) < prev   
Python Compiled Bytecode  |  2008-10-13  |  5KB  |  133 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from wx import Point, RectPS, TOP, BOTTOM, LEFT, RIGHT
  6. from traceback import print_exc
  7. from gui.toolbox import Monitor, alignment_to_string
  8. from gui.windowfx import move_smoothly
  9. from cgui import fadein, fadeout
  10. from common import prefprop, pref
  11. from logging import getLogger
  12. log = getLogger('popupstack')
  13.  
  14. def screenArea(monitor_n):
  15.     display_n = min(Monitor.GetCount() - 1, monitor_n)
  16.     return Monitor.All()[display_n].GetClientArea()
  17.  
  18.  
  19. class PopupStack(list):
  20.     
  21.     def __init__(self, monitor, position, padding = None, border = None):
  22.         self.monitor = monitor
  23.         self.corner = position
  24.         if padding is None:
  25.             padding = (0, 10)
  26.         
  27.         if border is None:
  28.             border = (10, 10)
  29.         
  30.         self.padding = Point(*padding)
  31.         self.border = Point(*border)
  32.         self.NextRect = None if TOP & self.corner else self.Up
  33.         self.OppositeRect = None if TOP & self.corner else self.Down
  34.  
  35.     
  36.     def __repr__(self):
  37.         return '<PopupStack %s monitor %d (%d popups)>' % (alignment_to_string(self.corner), self.monitor, len(self))
  38.  
  39.     
  40.     def ScreenRect(self):
  41.         return screenArea(self.monitor)
  42.  
  43.     ScreenRect = property(ScreenRect)
  44.     
  45.     def Up(self, prevRect, newSize):
  46.         border = self.border
  47.         padding = self.padding
  48.         if prevRect is None:
  49.             if LEFT & self.corner:
  50.                 pt = self.ScreenRect.BottomLeft + (border.x + padding.x, -(border.y))
  51.             else:
  52.                 pt = self.ScreenRect.BottomRight - (newSize.width + border.x + padding.x, border.y)
  53.         else:
  54.             pt = prevRect.TopLeft - Point(0, border.y + padding.y)
  55.         return RectPS(pt - Point(0, newSize.height), newSize)
  56.  
  57.     
  58.     def Down(self, prevRect, newSize):
  59.         border = self.border
  60.         padding = self.padding
  61.         if prevRect is None:
  62.             if LEFT & self.corner:
  63.                 pt = self.ScreenRect.TopLeft + (border.x + padding.x, border.y)
  64.             else:
  65.                 pt = self.ScreenRect.TopRight - (newSize.width + border.x + padding.x, -(border.y))
  66.         else:
  67.             pt = prevRect.BottomLeft + Point(0, border.y + padding.y)
  68.         return RectPS(pt, newSize)
  69.  
  70.     
  71.     def InitialPos(self, size):
  72.         return self.NextRect(None, size).Position
  73.  
  74.     
  75.     def Add(self, popup):
  76.         self.append(popup)
  77.         (popup, popup.OnClose) += (lambda userClose: self.Remove(popup))
  78.         self.DoPositions(popup)
  79.         popup._infader = fadein(popup, 0, popup.opacity_normal, 30)
  80.  
  81.     
  82.     def Remove(self, popup):
  83.         
  84.         try:
  85.             self.remove(popup)
  86.         except ValueError:
  87.             pass
  88.  
  89.         self.DoPositions()
  90.  
  91.     
  92.     def DoPositions(self, paging = None):
  93.         prevRect = None
  94.         for popup in self[:]:
  95.             
  96.             try:
  97.                 oldrect = popup.Rect
  98.             except wx.PyDeadObjectError:
  99.                 self.remove(popup)
  100.                 log.critical('dead Popup object in %r' % self)
  101.                 continue
  102.  
  103.             quick = False
  104.             desired = popup.DesiredSize
  105.             if popup.Hover or popup.has_focus:
  106.                 rect = RectPS(popup.Position, desired)
  107.                 if paging is popup:
  108.                     rect.y -= rect.height - oldrect.height
  109.                 
  110.             else:
  111.                 rect = self.NextRect(prevRect, desired)
  112.             popup._moved = True
  113.             self.SetPopupRect(popup, rect, quick = paging is popup)
  114.             prevRect = rect
  115.         
  116.  
  117.     slidetime = prefprop('notifications.popups.slide_ms', 140)
  118.     
  119.     def SetPopupRect(self, popup, rect, quick = False):
  120.         t = int(self.slidetime)
  121.         if t == 0:
  122.             quick = True
  123.         
  124.         oldrect = popup.Rect
  125.         if quick:
  126.             popup.SetRect(rect)
  127.         elif oldrect.Size != rect.Size:
  128.             popup.SetRect(oldrect.Position, rect.Size)
  129.         
  130.         move_smoothly(popup, rect.Position, time = t)
  131.  
  132.  
  133.